import { _decorator, ScrollView, Label, easing, Tween, assetManager, Camera, Node, Color, math, Sprite, SystemEvent, LabelComponent, SkinnedMeshRenderer, Prefab, v3, Vec3, SkeletalAnimation, ProgressBar, tween, WidgetComponent, Layout } from 'cc';

import BaseView from '../../Script/game/BaseView';
import { Bullet } from '../../Script/config/BaseData';
import Tool from '../../Script/tool/Tool'
// import { luckyBox } from './luckyBox';
import GD from '../../Script/config/GD';
import GDef from '../../Script/config/GDef';
const { bits } = math;
const { ccclass, property } = _decorator;

@ccclass('preEggList')
export class preEggList extends BaseView {
    @property({
        type: Node
    })
    nodeBg: Node = null;
    @property({
        type: Node
    })
    nodeContent: Node = null;
    @property({
        type: ScrollView
    })
    sv: ScrollView = null;
    private tweenMoveIn = null;
    private tweenMoveOut = null;
    private speed = 200;
    private stat = 0;//0out,1in
    private intStat = 0;
    private arr = [];
    onLoad() {
        this.arr = JSON.parse(JSON.stringify(GD.getEggList()));
        this.on(GDef.wdEvent.addEgg, this.addEgg);
        this.on(GDef.wdEvent.hideEggList, this.hideEggList);
        if (this.stat == 0) this.moveIn();
        else this.moveOut();
    }
    addEgg(tid: number, time: number, node3D: Node, useAni: boolean = true) {
        this.moveIn();
        let btn = Tool.createBtnEgg(this.nodeContent, tid, time, node3D, useAni);
    }
    hideEggList() {
        this.moveOut();
    }
    moveIn() {
        if (GDef.intStat <= 1) this.stat = 1;
    }
    moveOut() {
        if (GDef.intStat >= 1) this.stat = 0;
    }
    update(dt: number) {
        if (this.intStat == 0) {
            if (this.arr.length > 0) {
                this.addEgg(this.arr[0].tid, this.arr[0].time, null, false);
                this.arr.splice(0, 1);
            }
            else this.intStat = 1;
        }
        if (this.stat == 0 && this.nodeBg.getComponent(WidgetComponent).right > -78) this.nodeBg.getComponent(WidgetComponent).right -= 5;
        else if (this.stat == 1 && this.nodeBg.getComponent(WidgetComponent).right < 0) this.nodeBg.getComponent(WidgetComponent).right += 5;
    }
}
